#include "FishingNet.h"
#include "StaticData.h"
using namespace cocos2d;

FishingNet::FishingNet():_fishingNetSprite(0)
{
}

FishingNet::~FishingNet()
{
}

bool FishingNet::init()
{
	_fishingNetSprite=CCSprite::createWithSpriteFrameName(StaticData::getInstance()->stringFromKey("fishing_net"));
	addChild(_fishingNetSprite);
	return true;
}

FishingNet* FishingNet::create()
{
	FishingNet* pRet=new FishingNet;
	if(pRet&&pRet->init())
	{
		pRet->autorelease();
		return pRet;
	}
	else
	{
		delete pRet;
		pRet=0;
		return 0;
	}
}

void FishingNet::showAt(CCPoint pos)
{
	setPosition(pos);
	setScale(1);
	setVisible(true);
	stopAllActions();
	runAction(netAction());
}

CCAction* FishingNet::netAction()
{
	CCDelayTime* delayTime=CCDelayTime::create(1);
	CCHide* hide=CCHide::create();
	CCFiniteTimeAction* seq=CCSequence::create(delayTime,hide,0);
	return seq;
}

CCRect FishingNet::getCollisionArea()
{
	CCPoint origin=getParent()->convertToWorldSpace(getPosition());
	CCSize defaultSize=_fishingNetSprite->getContentSize();
	float scale=getScale();
	CCSize size(defaultSize.width*scale,defaultSize.height*scale);
	return CCRect(origin.x-size.width*0.5, origin.y-size.height*0.5, size.width, size.height);
}
